Skip to content

dock: Hand the focus to the tab that replaces a closed one - #3409

Merged
huacnlee merged 3 commits into
longbridge:mainfrom
sola-ryu:mv/dock-refocus-after-close
Oct 8, 2026
Merged

huacnlee merged 3 commits into
longbridge:mainfrom
sola-ryu:mv/dock-refocus-after-close

Conversation

@sola-ryu

@sola-ryu sola-ryu commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Closing a tab steals keyboard focus into nowhere: DockArea drops the panel, but the keystroke that follows lands on no view at all. If the closed panel held focus, the panel its group displays in its place should take it over.

This change makes DockArea::remove_panel check, before removing, whether the panel being closed contains the focused view. If it did, the panel the group now shows in its place (via active_panel) is focused. Closing a tab that never had focus changes nothing.

Two tests cover both sides:

  • dock_hands_the_focus_to_the_tab_that_replaces_a_closed_one — closing the focused tab moves focus to the newly visible tab.
  • dock_leaves_the_focus_alone_when_a_tab_without_it_closes — closing a background tab leaves focus where it was.

No public API changes; behavior-only fix.


This PR is 100% AI-generated: originally drafted with Claude on 2026-10-04, rebased onto current main, reviewed and validated by the contributor: cargo fmt --check, cargo clippy -p gpui-base --all-targets -- --deny warnings, and the dock test suite (4 passed, including the two new focus tests) are all green.

sola-ryu and others added 2 commits October 7, 2026 21:51
Closing the focused tab, by its close button, the Close menu item, or
`DockArea::remove_panel`, slides a neighbour into its place but leaves the
window's focus on the panel that has just gone. Nothing is focused
afterwards, so the next keystroke, including another close shortcut, lands
nowhere until the user clicks into the dock.

When the removed panel held the focus, the panel its group now displays
takes it over. Closing a tab that did not have the focus leaves the focus
where it is.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DHBYT8JhqczL6GhYZoKgww
huacnlee
huacnlee previously approved these changes Oct 8, 2026

@huacnlee huacnlee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the focus handoff and regression coverage. The fallback preserves focus chosen by on_removed, handles removal of an entire tab group, and skips hidden panels. All 9 Dock UI tests, relevant Clippy checks, and formatting checks passed.

@huacnlee
huacnlee enabled auto-merge (squash) October 8, 2026 06:50
@huacnlee
huacnlee disabled auto-merge October 8, 2026 06:50
@huacnlee
huacnlee enabled auto-merge (squash) October 8, 2026 06:50
@huacnlee
huacnlee merged commit 59cba65 into longbridge:main Oct 8, 2026
16 checks passed
linruohan pushed a commit to linruohan/gpui-component that referenced this pull request Oct 9, 2026
…e#3409)

Closing a tab steals keyboard focus into nowhere: `DockArea` drops the
panel, but the keystroke that follows lands on no view at all. If the
closed panel held focus, the panel its group displays in its place
should take it over.

This change makes `DockArea::remove_panel` check, before removing,
whether the panel being closed contains the focused view. If it did, the
panel the group now shows in its place (via `active_panel`) is focused.
Closing a tab that never had focus changes nothing.

Two tests cover both sides:

- `dock_hands_the_focus_to_the_tab_that_replaces_a_closed_one` — closing
the focused tab moves focus to the newly visible tab.
- `dock_leaves_the_focus_alone_when_a_tab_without_it_closes` — closing a
background tab leaves focus where it was.

No public API changes; behavior-only fix.

---
This PR is 100% AI-generated: originally drafted with Claude on
2026-10-04, rebased onto current main, reviewed and validated by the
contributor: `cargo fmt --check`, `cargo clippy -p gpui-base
--all-targets -- --deny warnings`, and the dock test suite (4 passed,
including the two new focus tests) are all green.

---------

Co-authored-by: Sola <sola-ryu@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-authored-by: Jason Lee <huacnlee@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants